#Include <MyLibrary.au3>

 
Global $WinTitle = "World of Warcraft"
Global $WinSize = GetWinSize($WinTitle)
Global $Lite = ObjCreate("SERFLITEMAX20.Core.Main")
$Lite.Start
while not $Lite.HasStarted
wend

WinActivate($WinTitle)
WinWaitActive($WinTitle)
dim $facing = $Lite.Player.Facing;
dim $buffer = 0.1
sleep(5000)
while True
	$Lite.Player.Update
	dim  $next = $Lite.Player.Facing;
	dim  $direction = ""
	dim  $points = 0
	
	Calc($facing,$next, $direction, $points)
	
	while not $direction = "SAME" and $points > $buffer
		;local $amount = 
		if $direction = "LEFT" Then
			send("aaa")
		endif
		if $direction = "RIGHT" Then
			send("ddd")
		endif
		sleep(200)
		$Lite.Player.Update
		$next = $Lite.Player.Facing
		Calc($facing,$next, $direction, $points)
	wend
	sleep(50)
wend
;MsgBox(0,"test",$direction )
;sleep(1000)

Exit

func Calc($current,$next,  $direction,  $points)
 
	$direction = ""

	$points = 0
	dim  $resultvalue 
	dim $maxradiant = 6.25
	dim $maxradianthalf = $maxradiant / 2

	dim $max = Max($current,$next)
	dim $min = Min($current, $next)


	dim $result = $max - $min
	dim $result2 = 0;
	if $result > $maxradianthalf then
		$result2 = $result - $maxradianthalf;
	else
		$result2 = $result + $maxradianthalf;
	endif

	if not $result2 =  $maxradianthalf then
	
		if  $result2 > $maxradianthalf then
		
			$resultvalue = "LEFT";
		
		else
		
			$resultvalue = "RIGHT";
		endif
	
	else
	
		$resultvalue = "SAME";
	endif

	$direction = $resultvalue;

	$points = 0
	if  $resultvalue =  "RIGHT" then
	
		$points = $min
	endif
	if $resultvalue = "LEFT" then
	
		$points = $result
	endif
 EndFunc  